﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using cmsservice.Common;

/// <summary>
///Cache 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class Cache2 : System.Web.Services.WebService {

    public Cache2 () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public void Add(string key,string content,int m) {
        DateTime now = DateTime.Now.AddMinutes(m);
        MemcachedTools.News2Add(key,content,now);
    }

    [WebMethod]
    public string Get(string key)
    {
        string str=MemcachedTools.News2Get<string>(key);
        str = str == null ? "" : str;
        return str;
    }

    [WebMethod(Description="获取股票医生的memcached")]
    public string GetGpysJson(string key)
    {
        MemcachedGpysTools cache = new MemcachedGpysTools();
        var data = cache.Get<byte[]>(key);
        string str = System.Text.Encoding.GetEncoding("utf-8").GetString(data);
        return str;
    }

    [WebMethod(Description = "获取股票医生的memcached")]
    public string GetGpysJson2(string key,string coding)
    {
        MemcachedGpysTools cache = new MemcachedGpysTools();
        var data = cache.Get<byte[]>(key);
        string str = System.Text.Encoding.GetEncoding(coding).GetString(data);
        return str;
    }

}
